#define _CRT_SECURE_NO_WARNINGS 1
#include"qsort.h"
int com_stu_by_age(const void* p1, const void* p2)
{
	return ((struct stu*)p1)->age - ((struct stu*)p2)->age;
}
int com_stu_by_name(const void* p1, const void* p2)
{
	return strcmp(((struct stu*)p1)->name, ((struct stu*)p2)->name);

}
void printf_arr(struct stu* arr, int sz)
{
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%s %d\n", (arr + i)->name, (arr + i)->age);
	}
	printf("\n");
}
void swap(char *p1,char *p2,size_t size)
{
	int i = 0;
	for (i = 0; i < size; i++)
	{
		char temp = *p1;
		*p1 = *p2;
		*p2 = temp;
		p1++;
		p2++;
	}
}

void bubble_sort(void* base, size_t num, size_t size, int (*compar)(const void* p1,const void* p2))
{
	int i = 0;
	for (i = 0; i < num - 1; i++)
	{
		int j = 0;
		for (j = 0; j < num - 1 - i; j++)
		{
			if(  compar (  (char*)base + j * size, (char*)base + (j+1) * size   ) > 0  )
			{
				swap( (char*)base + j * size, (char*)base + (j + 1) * size ,size);
			}

		}
	}
}